package tako.wisers.com.android.apis.event;

import java.util.Hashtable;

import tako.wisers.com.android.apis.handler.Handler;

@SuppressWarnings("unchecked")
public class EventBus extends Hashtable<String, Handler> {
	private static final long serialVersionUID = -87441874614421851L;
	private static final EventBus mbus = new EventBus();

	private EventBus() {
	}

	public static EventBus getInstance() {
		return mbus;
	}

	public void addListener(Event event, Handler handler) {
		put(event.toString(), handler);
	}

	public void executeEvent(final Event event) {
		new Thread(new Runnable() {
			@Override
			public void run() {
				String key = event.toString();
				if (containsKey(key))
					get(event.toString()).execute(event);
			}
		}).start();
		System.gc();
	}

	public void signinEvent(int id, Handler handler, int eventType) {
		Event event = new Event(id, eventType, false);
		addListener(event, handler);
	}
}
